package post;

/*
 * ------------------- CHANGE LOG -----------------------------------
 * DATE             MOD BY              DESCRIPTION
 * 01/31/11         Pia                 Created class
 *
 *
 */

import java.io.FileNotFoundException;
import post.Catalog;
import java.io.IOException;
import java.io.File;

public class Manager {
    private boolean storeStockisFull = false;
    private static File salesLog;
    private static File catalog;
    //private static Post post;
    public void openStore( store st ){
        storeStockisFull = true;    //inifinite stock

        //make sure a sales log file exists for later
        try{
            salesLog = new File("Store"+File.separator+"sales.txt");
            catalog = new File("Store"+File.separator+"products.txt");
            boolean saleLogSuccess = salesLog.createNewFile();  //create salesLog if necessary
            boolean catalogSuccess = catalog.createNewFile();   //create catalog if necessary
            salesLog.setWritable(true, false);  //set write permissions
            st.open(new Catalog(catalog), salesLog);    //open store, load catalog and salesLog
        } catch (IOException e) {
            System.out.print("Error: IOException caught\n\n");
        }
    }//end openStore

    public boolean getStock(){return storeStockisFull;} //store always has enough stock

    public static void main(String args[]) throws FileNotFoundException, IOException
    {
        Manager thisGuy = new Manager();
        store st = new store();
        thisGuy.openStore( st );    //manager opens store
        Post post = new Post();     //sets up post
        post.start(st.getCatalog(), salesLog);  //allows post to handle transaction
    }
}//end Manager class

